
/**
 * 游戏入口配置
 */
class Main extends eui.UILayer {

    private loadingView: LoadingView = new LoadingView();

    public constructor() {
        super();
        Context.getInstance().commonViewManager.loadingView = this.loadingView;
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
    } 
 
    private addToStage(event: egret.Event) {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
        this.stage.registerImplementation("eui.IAssetAdapter",new AssetAdapter());
        this.stage.registerImplementation("eui.IThemeAdapter",new ThemeAdapter());
        if(DeviceUtils.isPC) {
            Context.getInstance().setScaleMode(egret.StageScaleMode.SHOW_ALL);
        }
        ResManager.get.addConfig("resource/default.res.json","resource/");
        ResManager.get.loadConfig(this.onConfigComplete,this);
        
        this.addChild(this.loadingView);
    }

    private onConfigComplete(): void {
        var theme = new eui.Theme("resource/default.thm.json",this.stage);
        theme.addEventListener(eui.UIEvent.COMPLETE,this.onThemeLoadComplete,this);
    } 

    private onThemeLoadComplete() {
        var app = new App(this);
        app.start();
    }

}
